$(function(){
    "use strict";
    // 点击出现搜索框
    $('.hidden_box_showBox').click(function(){
        $(this).siblings('.hidden_box_hiddenBox').toggleClass('active')
        if($(this).children('i').hasClass('icon-jiantou')){
            $(this).children('i').removeClass('icon-jiantou').addClass('icon-jiantou-top')
        }else{
            $(this).children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        }
    })

    // 当确定搜索时
    $('.hiddenBox_list_btn').on('click','button',function(){
        $('.hidden_box_hiddenBox').removeClass('active')
        $('.hidden_box_showBox').children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        if($(this).html() == '确定'){
            $('#dateVal').html(window.choose_queryDateVal||'全部')
            // let startTime = window.query_time_start
            // let endTime = window.query_time_end
            let time = $(this).closest('.hidden_box_hiddenBox').find('[data-query="time"]').val()
            let startTime = time.split(' - ')[0]
            let endTime = time.split(' - ')[1]
            console.log(startTime,endTime)
            let name = $(this).closest('.hidden_box_hiddenBox').find('[data-query="name"]').val()
            let num = $(this).closest('.hidden_box_hiddenBox').find('[data-query="num"]').val()
            window.location.href = `/Admin/Device/index?start_time=${startTime}&end_time=${endTime}&dev_name=${name}&dev_sn=${num}`
        }else{
            window.choose_queryDateVal = null
        }
    })

    /**
     *全选的功能
     */
    $('#checkAll').on('click',function(){
        var checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for(var i=0;i<checkboxs.length;i++){
            var checkbox=checkboxs[i];
            checkbox.checked=this.checked;
        }
    })
    $('#table_table').on('click','input[type=checkbox]:not("#checkAll")',function(){
        "use strict";
        var isCheckedAll = true;
        var checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for (var i = 0; i < checkboxs.length; i++) {
            if (!checkboxs[i].checked) {
                isCheckedAll = false;
                break;
            }
        }
        $('#checkAll')[0].checked = isCheckedAll;
    })

    /*当点击添加按钮时*/
    $('.operation_btn').on('click','a',function(e){
        e.preventDefault();
        if( $(this).html() == '添加' ){
            let add_people = $(this).attr('href');
            $(`[lll=${add_people}]`).addClass('active')
        }
        if( $(this).html() == '批量删除' ){
            var checkboxs =$('input[type=checkbox]:not("#checkAll")');
            var len = 0;
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    continue
                }else{
                    len++
                }
            }
            if(len == checkboxs.length){
                $('#yz_modal').html('您还没有选择人员！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }
            let _delete = $(this).attr('href');
            $(_delete).addClass('active')
        }
        if( $(this).html() == '批量导入' ){
            let showbox_id = $(this).attr('href');
            $(showbox_id).addClass('active')
        }
    })

    // 批量删除
    $('.delete_tip_btn_box').on('click','button',function(){
        "use strict";
        let delete_arr = [];
        if($(this).html() == '确认'){
            let checkboxs =$('#table_table input[type=checkbox]:not("#checkAll")');
            for (let i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    delete_arr.push( $(checkboxs[i]).closest('tr[data-index]').attr('data-index') )
                }else{
                    continue;
                }
            }
            $.ajax({
                url:'/Admin/Device/multiDelDevice',
                type:'post',
                data:{
                    dev_id: delete_arr
                },
                success:function(data){
                    if(data.code==1){
                        for(let r = 0; r < delete_arr.length; r++){
                            $('#table_table').children('tbody').children(`[data-index=${delete_arr[r]}]`).remove();
                        }
                        $('#delete').removeClass('active')
                        window.location.href = `/Admin/Device/index`//强制刷新
                    }
                }
            })
        }else{
            $('#delete').removeClass('active')
        }

    })

    // 当点击编辑按钮时
    $('#table_table').on('click','.edit_table',function(e){
        e.preventDefault();
        let operation = $(this).attr('href');
        let operation_id = $(this).closest('tr').attr('data-index');
        if( operation == 'edit_people'){
            let that = this;
            $.ajax({
                url:'/Admin/Device/editDevice',
                type:'get',
                data:{
                    id:operation_id
                },
                success:function(data){
                    console.log(data)
                    if(data.code==1){
                        let datas = data.data;
                        $(`[lll=${operation}]`).find('[add_name="edit_num"]').val(datas.dev_sn)
                        $(`[lll=${operation}]`).find('[add_name="edit_name"]').val(datas.dev_name)
                        //类型
                        let edit_typeList = $(`[lll=${operation}]`).find('[add_name="edit_type"]').children()
                        for(var typei=0;typei<edit_typeList.length;typei++){
                            var edit_typeVal = $(edit_typeList[typei]).children('span').html();
                            if(edit_typeVal == datas.dev_type){
                                $(edit_typeList[typei]).children('i').addClass('icon-Raidobox-selectedRai').removeClass('icon-Raidobox')
                                $(edit_typeList[typei]).siblings().children('i').removeClass('icon-Raidobox-selectedRai').addClass('icon-Raidobox')
                            }
                        }
                        //用途
                        let edit_yongtuList = $(`[lll=${operation}]`).find('[add_name="edit_yongtu"]').children()
                        for(var yongtui=0;yongtui<edit_yongtuList.length;yongtui++){
                            var edit_yongtuVal = $(edit_yongtuList[yongtui]).children('span').html();
                            if(edit_yongtuVal == datas.dev_yongtu){
                                $(edit_yongtuList[yongtui]).children('i').addClass('icon-Raidobox-selectedRai').removeClass('icon-Raidobox')
                                $(edit_yongtuList[yongtui]).siblings().children('i').removeClass('icon-Raidobox-selectedRai').addClass('icon-Raidobox')
                            }
                        }
                        $(`[lll=${operation}]`).find('[add_name="edit_modelSpecifications"]').val(datas.dev_desc)
                        $(`[lll=${operation}]`).find('[add_name="edit_power"]').val(datas.dev_power)
                        $(`[lll=${operation}]`).find('[add_name="edit_buy_date"]').val(datas.dev_time)
                        //设备状态
                        // let edit_stateList = $(`[lll=${operation}]`).find('[add_name="edit_state"]').children()
                        // for(var statei=0;statei<edit_typeList.length;statei++){
                        //     var edit_stateVal = $(edit_stateList[statei]).children('span').html();
                        //     if(edit_stateVal == datas.dev_status){
                        //         $(edit_stateList[statei]).children('i').addClass('icon-Raidobox-selectedRai').removeClass('icon-Raidobox')
                        //         $(edit_stateList[statei]).siblings().children('i').removeClass('icon-Raidobox-selectedRai').addClass('icon-Raidobox')
                        //     }
                        // }
                        // $(`[lll=${operation}]`).find('[add_name="edit_depreciationMethod"]').val(datas.dev_depreciation)
                        $(`[lll=${operation}]`).find('[add_name="edit_original_price"]').val(datas.dev_price)
                        $(`[lll=${operation}]`).find('[add_name="edit_residual"]').val(parseFloat(datas.dev_can_lv))
                        $(`[lll=${operation}]`).find('[add_name="edit_Estimate_price"]').val(datas.dev_can)
                        $(`[lll=${operation}]`).find('[add_name="edit_Estimate_userTime"]').val(datas.dev_use_month)
                        $(`[lll=${operation}]`).find('[add_name="edit_Estimate_userTime"]').css('border-color','#E4E5E6')
                        $(`[lll=${operation}]`).find('[add_name="edit_userTime_ed"]').val(datas.dev_zhe_month)
                        $(`[lll=${operation}]`).find('[add_name="edit_userPrice_mon"]').val(datas.dev_month_money)
                    }
                }
            })
            window.sessionStorage['operation_id']=operation_id
            $(`[lll=${operation}]`).addClass('active');
        }
    })

    // 单选按钮样式的变化
    $('.table_btn_list_radio_list').on('click','li',function(e){
        "use strict";
        $(this).children('i').addClass('icon-Raidobox-selectedRai').removeClass('icon-Raidobox')
        $(this).siblings().children('i').removeClass('icon-Raidobox-selectedRai').addClass('icon-Raidobox')
    })

    // 残值率-判断
    $('#add_people').find('[add_name=add_residual]').blur(function(e){
        let value = $(this).val()
        if(value>10||value<0){
            $(this).css('border-color','#ff0000')
            $(this).val('')
        }else{
            $(this).css('border-color','#E4E5E6')
        }
    })
    //预计使用月份-判断
    $('#add_people').find('[add_name=add_Estimate_userTime]').blur(function(e){
        let value = $(this).val()
        let userTime_ed = $('#add_people').find('[add_name=add_userTime_ed]').val()
        if(value>120){
            $(this).css('border-color','#ff0000')
            $(this).val('')
            $(this).attr('placeholder','不得超过120个月')
        }else if(value<=0){
            $(this).css('border-color','#ff0000')
            $(this).val('')
            $(this).attr('placeholder','不得小于0个月')
        }else{
            if(userTime_ed>value){
                $(this).css('border-color','#ff0000')
                $(this).val('')
                $(this).attr('placeholder','不得小于已折旧月份')
            }else{
                $(this).css('border-color','#E4E5E6')
                // $(this).attr('placeholder','不得超过120个月')
            }
        }
    })
    // 已使用月份，不得大于预计使用月份
    $('#add_people').find('[add_name=add_userTime_ed]').blur(function(e){
        let value = $(this).val()
        let userTime = $('#add_people').find('[add_name=add_Estimate_userTime]')//预计使用月份
        if(value>userTime){
            $(this).css('border-color','#ff0000')
            $(this).val('')
            $(this).attr('placeholder','不得小于已折旧月份')
        }else{
            $(this).css('border-color','#E4E5E6')
        }
    })
    /**
     * 确认按钮点击时
     */
    // var tbodyLen = $('#table_table').children('tbody').length;
    $('#add_btn').click(function(){

        let add_num = $(this).closest('[lll]').find('[add_name=add_num]').val();
        let add_name = $(this).closest('[lll]').find('[add_name=add_name]').val();
        let add_type = $(this).closest('[lll]').find('[add_name=add_type]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
        let add_yongtu = $(this).closest('[lll]').find('[add_name=add_yongtu]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
        let add_modelSpecifications = $(this).closest('[lll]').find('[add_name=add_modelSpecifications]').val();
        let add_power = $(this).closest('[lll]').find('[add_name=add_power]').val();
        let time = $(this).closest('[lll]').find('[add_name=add_buy_date]').val();
        // let time = window.buy_date;
        // let add_state = $(this).closest('[lll]').find('[add_name=add_state]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
        // let add_depreciationMethod = $(this).closest('[lll]').find('[add_name=add_depreciationMethod]').val();
        // $(this).closest('[lll]').find('[add_name=add_depreciationMethod]').val('年限平均法');
        let add_original_price = $(this).closest('[lll]').find('[add_name=add_original_price]').val();
        let add_residual = $(this).closest('[lll]').find('[add_name=add_residual]').val();
        let add_Estimate_price = $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val();
        let add_Estimate_userTime = $(this).closest('[lll]').find('[add_name=add_Estimate_userTime]').val();
        let add_userTime_ed = $(this).closest('[lll]').find('[add_name=add_userTime_ed]').val();
        let add_userPrice_mon = $(this).closest('[lll]').find('[add_name=add_userPrice_mon]').val();

        if(add_num == '' || add_name == '' || add_type == '' || add_modelSpecifications == '' || time == '' || add_original_price == '' || add_residual == '' || add_Estimate_userTime == '' || add_userTime_ed == ''){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        // if(add_Estimate_userTime == 0){
        //     return
        // }

        if( $(this).attr('lock') ) return
        $(this).attr('lock','lock')

        let that = this
        $.ajax({
            url:'/Admin/Device/addDevice',
            type:'post',
            data:{
                dev_name: add_name,
                dev_sn: add_num,
                dev_type: add_type,
                dev_yongtu: add_yongtu,
                dev_desc: add_modelSpecifications,
                dev_price: add_original_price,
                dev_time: time,
                dev_use_month: add_Estimate_userTime,
                // dev_status: add_state,
                // dev_depreciation: add_depreciationMethod,
                dev_can: add_Estimate_price,
                dev_zhe_month: add_userTime_ed,
                dev_power: add_power,
                dev_can_lv: add_residual,
                dev_month_money: add_userPrice_mon
            },
            success:function(data){
                // console.log(data)
                if(data.code==1){
                       // var peopleTableHTML = $('#table_table').children('tbody').html()
                       let peopleTableHTML = `
                                    <tr data-index="${data.id}">
                                            <td><input type="checkbox" class="checkboxStyle"></td>
                                            <td data-name="edit_num">${add_num}</td>
                                            <td data-name="edit_name">${add_name}</td>
                                            <td data-name="edit_type">${add_type}</td>
                                            <td data-name="edit_yongtu">${add_yongtu}</td>
                                            <td data-name="edit_modelSpecifications">${add_modelSpecifications}</td>
                                            <td data-name="edit_time">${time}</td>
                                            <td data-name="edit_original_price">${add_original_price}</td>
                                            <td data-name="edit_residual">${add_residual}%</td>
                                            <td data-name="edit_Estimate_userTime">${add_Estimate_userTime}</td>
                                            <td data-name="edit_userPrice_mon">${add_userPrice_mon}</td>
                                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                                        </tr>
                            `
                        $('#table_table').children('tbody').prepend(peopleTableHTML)

                        $(that).closest('[lll]').find('[add_name]:not([add_name=add_depreciationMethod])').val('')
                        $(that).parent().parent().removeClass('active')
                        $(that).closest('[lll]').removeClass('active')
                }

                $(that).removeAttr('lock')
            }
        })

    })
    /*预计残值 自动计算*/
    $('[add_name=add_original_price]').blur(function(){
        let add_original_price = $(this).closest('[lll]').find('[add_name=add_original_price]').val();//资产原值
        let add_Estimate_price = $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val();//残值
        let add_Estimate_userTime = $(this).closest('[lll]').find('[add_name=add_Estimate_userTime]').val();//折旧月份
        let add_residual = $(this).closest('[lll]').find('[add_name=add_residual]').val();//残值率
        if(add_original_price&&add_residual){//算残值
            let add_Estimate_price = (Number(add_original_price)*Number(add_residual))/100
            $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val(add_Estimate_price)
        }else{
            $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val('')
            return
        }
        if(add_original_price&&add_Estimate_price&&add_Estimate_userTime){//算月折旧额
            let add_userPrice_mon = (Number(add_original_price)-Number(add_Estimate_price))/Number(add_Estimate_userTime)
            $(this).closest('[lll]').find('[add_name=add_userPrice_mon]').val(add_userPrice_mon.toFixed(2))
        }else{
            $(this).closest('[lll]').find('[add_name=add_userPrice_mon]').val('')
            return
        }
    })
    $('[add_name=add_residual]').blur(function(){
        let add_original_price = $(this).closest('[lll]').find('[add_name=add_original_price]').val();
        let add_residual = $(this).closest('[lll]').find('[add_name=add_residual]').val();
        if(add_original_price&&add_residual){//算残值
            let add_Estimate_price = (Number(add_original_price)*Number(add_residual))/100
            $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val(add_Estimate_price)
        }else{
            $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val('')
            return
        }
    })
    /*月折旧额 自动计算*/
    $('[add_name=add_Estimate_userTime]').blur(function(){
        let add_original_price = $(this).closest('[lll]').find('[add_name=add_original_price]').val();//资产原值
        let add_Estimate_price = $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val();//残值
        let add_Estimate_userTime = $(this).closest('[lll]').find('[add_name=add_Estimate_userTime]').val();//折旧月份
        if(add_original_price&&add_Estimate_price&&add_Estimate_userTime){
            let add_userPrice_mon = (Number(add_original_price)-Number(add_Estimate_price))/Number(add_Estimate_userTime)
            $(this).closest('[lll]').find('[add_name=add_userPrice_mon]').val(add_userPrice_mon.toFixed(2))
        }else{
            $(this).closest('[lll]').find('[add_name=add_userPrice_mon]').val('')
            return
        }
    })

    /**
     * 确认并新增按钮点击时
     */
    $('#add_AddNew_btn').click(function(){

        let add_num = $(this).closest('[lll]').find('[add_name=add_num]').val();
        let add_name = $(this).closest('[lll]').find('[add_name=add_name]').val();
        let add_type = $(this).closest('[lll]').find('[add_name=add_type]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
        let add_yongtu = $(this).closest('[lll]').find('[add_name=add_yongtu]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
        let add_modelSpecifications = $(this).closest('[lll]').find('[add_name=add_modelSpecifications]').val();
        let add_power = $(this).closest('[lll]').find('[add_name=add_power]').val();
        let time = $(this).closest('[lll]').find('[add_name=add_buy_date]').val();
        // let time = window.buy_date;
        // let add_state = $(this).closest('[lll]').find('[add_name=add_state]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
        // let add_depreciationMethod = $(this).closest('[lll]').find('[add_name=add_depreciationMethod]').val();
        // $(this).closest('[lll]').find('[add_name=add_depreciationMethod]').val('年限平均法');
        let add_original_price = $(this).closest('[lll]').find('[add_name=add_original_price]').val();
        let add_residual = $(this).closest('[lll]').find('[add_name=add_residual]').val();
        let add_Estimate_price = $(this).closest('[lll]').find('[add_name=add_Estimate_price]').val();
        let add_Estimate_userTime = $(this).closest('[lll]').find('[add_name=add_Estimate_userTime]').val();
        let add_userTime_ed = $(this).closest('[lll]').find('[add_name=add_userTime_ed]').val();
        let add_userPrice_mon = $(this).closest('[lll]').find('[add_name=add_userPrice_mon]').val();

        if(add_num == '' || add_name == '' || add_type == '' || add_modelSpecifications == '' || time == '' || add_original_price == '' || add_residual == '' || add_Estimate_userTime == '' || add_userTime_ed == ''){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        // if(add_Estimate_userTime == 0){
        //     return
        // }
        //防止重复点击按钮
        if( $(this).attr('lock') ) return
        $(this).attr('lock','lock')

        let that = this
        $.ajax({
            url:'/Admin/Device/addDevice',
            type:'post',
            data:{
                dev_name: add_name,
                dev_sn: add_num,
                dev_type: add_type,
                dev_yongtu: add_yongtu,
                dev_desc: add_modelSpecifications,
                dev_price: add_original_price,
                dev_time: time,
                dev_use_month: add_Estimate_userTime,
                // dev_status: add_state,
                // dev_depreciation: add_depreciationMethod,
                dev_can: add_Estimate_price,
                dev_zhe_month: add_userTime_ed,
                dev_power: add_power,
                dev_can_lv: add_residual,
                dev_month_money: add_userPrice_mon
            },
            success:function(data){
                console.log(data)
                if(data.code==1){
                    // var peopleTableHTML = $('#table_table').children('tbody').html()
                    let peopleTableHTML = `
                                    <tr data-index="${data.id}">
                                            <td><input type="checkbox" class="checkboxStyle"></td>
                                            <td data-name="edit_num">${add_num}</td>
                                            <td data-name="edit_name">${add_name}</td>
                                            <td data-name="edit_type">${add_type}</td>
                                            <td data-name="edit_yongtu">${add_yongtu}</td>
                                            <td data-name="edit_modelSpecifications">${add_modelSpecifications}</td>
                                            <td data-name="edit_time">${time}</td>
                                            <td data-name="edit_original_price">${add_original_price}</td>
                                            <td data-name="edit_residual">${add_residual}%</td>
                                            <td data-name="edit_Estimate_userTime">${add_Estimate_userTime}</td>
                                            <td data-name="edit_userPrice_mon">${add_userPrice_mon}</td>
                                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                                        </tr>
                            `
                    $('#table_table').children('tbody').prepend(peopleTableHTML)

                    $(that).closest('[lll]').find('[add_name]:not([add_name=add_depreciationMethod])').val('')
                    // $(that).parent().parent().removeClass('active')
                    // $(that).closest('[lll]').removeClass('active')
                }
                $(that).removeAttr('lock')
            }
        })
    })

    // 残值率-判断
    $('#edit_people').find('[add_name=edit_residual]').blur(function(e){
        let value = $(this).val()
        if(value>10||value<0){
            $(this).css('border-color','#ff0000')
            $(this).val('')
        }else{
            $(this).css('border-color','#E4E5E6')
        }
    })
    //使用月份-判断
    $('#edit_people').find('[add_name=edit_Estimate_userTime]').blur(function(e){
        let value = Number($(this).val())
        let userTime_ed = Number($('#edit_people').find('[add_name=edit_userTime_ed]').val())
        // if(value>120||value<0){
        //     $(this).css('border-color','#ff0000')
        //     $(this).val('')
        //     $(this).attr('placeholder','不得超过120个月')
        // }else{
        //     if(value<userTime_ed){
        //         $(this).css('border-color','#ff0000')
        //         $(this).val('')
        //         $(this).attr('placeholder','不得小于已折旧月份')
        //     }else{
        //         $(this).css('border-color','#E4E5E6')
        //         $(this).attr('placeholder','不得超过120个月')
        //     }
        // }
        if(value>120){
            $(this).css('border-color','#ff0000')
            $(this).val('')
            $(this).attr('placeholder','不得超过120个月')
        }else if(value<=0){
            $(this).css('border-color','#ff0000')
            $(this).val('')
            $(this).attr('placeholder','不得小于或等于0个月')
        }else{
            if(userTime_ed>value){
                console.log('edit:'+'已折旧大于折旧')
                $(this).css('border-color','#ff0000')
                $(this).val('')
                $(this).attr('placeholder','不得小于已折旧月份')
            }else{
                console.log('edit:'+'ok')
                console.log('zhejiu:'+value)
                console.log('yizhejiu:'+userTime_ed)
                $(this).css('border-color','#E4E5E6')
                /*$(this).attr('placeholder','不得超过120个月')*/
            }
        }
    })
    // 已使用月份，不得大于预计使用月份
    $('#edit_people').find('[add_name=edit_userTime_ed]').blur(function(e){
        let value = $(this).val()
        let userTime = $('#add_people').find('[add_name=add_Estimate_userTime]')//预计使用月份
        if(value>userTime){
            console.log('edit:'+'已折旧大于折旧')
            $(this).css('border-color','#ff0000')
            $(this).val('')
            $(this).attr('placeholder','不得小于已折旧月份')
        }else{
            $(this).css('border-color','#E4E5E6')
        }
    })

    /**
     * 保存按钮点击时
     */
    $('#save_btn').click(function(){
        if( $(this).html() == '保存' ){

            //防止重复点击按钮
            if( $(this).attr('lock') ) return
            $(this).attr('lock','lock')

            let edit_num = $(this).closest('[lll]').find('[add_name=edit_num]').val();
            let edit_name = $(this).closest('[lll]').find('[add_name=edit_name]').val();
            let edit_type = $(this).closest('[lll]').find('[add_name=edit_type]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
            let edit_yongtu = $(this).closest('[lll]').find('[add_name=edit_yongtu]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
            let edit_modelSpecifications = $(this).closest('[lll]').find('[add_name=edit_modelSpecifications]').val();
            let edit_power = $(this).closest('[lll]').find('[add_name=edit_power]').val();
            let time = $(this).closest('[lll]').find('[add_name=edit_buy_date]').val();
            // let edit_state = $(this).closest('[lll]').find('[add_name=edit_state]').children().children('i.icon-Raidobox-selectedRai').siblings('span').html()
            // let edit_depreciationMethod = $(this).closest('[lll]').find('[add_name=edit_depreciationMethod]').val();
            let edit_original_price = $(this).closest('[lll]').find('[add_name=edit_original_price]').val();
            let edit_residual = $(this).closest('[lll]').find('[add_name=edit_residual]').val();
            let edit_Estimate_price = $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val();
            let edit_Estimate_userTime = $(this).closest('[lll]').find('[add_name=edit_Estimate_userTime]').val();
            let edit_userTime_ed = $(this).closest('[lll]').find('[add_name=edit_userTime_ed]').val();
            let edit_userPrice_mon = $(this).closest('[lll]').find('[add_name=edit_userPrice_mon]').val();

            let operation_id = window.sessionStorage['operation_id'];
            let that = this;
            if(edit_num == '' || edit_name == '' || edit_type == '' || edit_modelSpecifications == '' || time == '' || edit_original_price == '' || edit_residual == '' || edit_Estimate_userTime == '' || edit_userTime_ed == ''){
                $('#yz_modal').html('您有内容没有填写完整！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }
            // if(edit_Estimate_userTime == 0){
            //     return
            // }
            $.ajax({
                url:'/Admin/Device/editDevice',
                type:'post',
                data:{
                    id: operation_id,
                    dev_name: edit_name,
                    dev_sn: edit_num,
                    dev_type: edit_type,
                    dev_yongtu: edit_yongtu,
                    dev_desc: edit_modelSpecifications,
                    dev_price: edit_original_price,
                    dev_time: time,
                    dev_use_month: edit_Estimate_userTime,
                    // dev_status: edit_state,
                    // dev_depreciation: edit_depreciationMethod,
                    dev_can: edit_Estimate_price,
                    dev_zhe_month: edit_userTime_ed,
                    dev_power: edit_power,
                    dev_can_lv: edit_residual,
                    dev_month_money: edit_userPrice_mon
                },
                success:function(data){
                    if(data.code==1){
                        var tableHTML = $('#table_table').children('tbody').find(`[data-index=${operation_id}]`)
                        tableHTML.children('[data-name=edit_num]').html(edit_num)
                        tableHTML.children('[data-name=edit_time]').html(time)
                        tableHTML.children('[data-name=edit_name]').html(edit_name)
                        tableHTML.children('[data-name=edit_type]').html(edit_type)
                        tableHTML.children('[data-name=edit_yongtu]').html(edit_yongtu)
                        tableHTML.children('[data-name=edit_modelSpecifications]').html(edit_modelSpecifications)
                        // tableHTML.children('[data-name=edit_state]').html(edit_state)
                        tableHTML.children('[data-name=edit_original_price]').html(edit_original_price)
                        tableHTML.children('[data-name=edit_residual]').html(edit_residual)
                        tableHTML.children('[data-name=edit_Estimate_userTime]').html(edit_Estimate_userTime)
                        tableHTML.children('[data-name=edit_userPrice_mon]').html(edit_userPrice_mon)
                        $(that).parent().parent().removeClass('active')
                    }
                    $(that).removeAttr('lock')
                }
            })
        }

    })
    /*预计残值 自动计算*/
    $('[add_name=edit_original_price]').blur(function(){
        let edit_original_price = $(this).closest('[lll]').find('[add_name=edit_original_price]').val();//资产原值
        let edit_Estimate_price = $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val();//残值
        let edit_Estimate_userTime = $(this).closest('[lll]').find('[add_name=edit_Estimate_userTime]').val();//使用分月
        
        let edit_residual = $(this).closest('[lll]').find('[add_name=edit_residual]').val();//残值率
        if(edit_original_price&&edit_residual){
            let add_Estimate_price = (Number(edit_original_price)*Number(edit_residual))/100
            // console.log(add_Estimate_price)
            $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val(add_Estimate_price)
        }else{
            $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val('')
            return
        }
        if(edit_original_price&&edit_Estimate_price&&edit_Estimate_userTime){
            let edit_userPrice_mon = (Number(edit_original_price)-Number(edit_Estimate_price))/Number(edit_Estimate_userTime)
            $(this).closest('[lll]').find('[add_name=edit_userPrice_mon]').val(edit_userPrice_mon.toFixed(2))
        }else{
            $(this).closest('[lll]').find('[add_name=edit_userPrice_mon]').val('')
            return
        }
    })
    $('[add_name=edit_residual]').blur(function(){
        let edit_original_price = $(this).closest('[lll]').find('[add_name=edit_original_price]').val();
        let edit_residual = $(this).closest('[lll]').find('[add_name=edit_residual]').val();
        if(edit_original_price&&edit_residual){
            let edit_Estimate_price = (Number(edit_original_price)*Number(edit_residual))/100
            $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val(edit_Estimate_price)
        }else{
            $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val('')
            return
        }
    })
    /*月折旧额 自动计算*/
    $('[add_name=edit_Estimate_userTime]').blur(function(){
        let edit_original_price = $(this).closest('[lll]').find('[add_name=edit_original_price]').val();//资产原值
        let edit_Estimate_price = $(this).closest('[lll]').find('[add_name=edit_Estimate_price]').val();//残值
        let edit_Estimate_userTime = $(this).closest('[lll]').find('[add_name=edit_Estimate_userTime]').val();//折旧月份
        if(edit_original_price&&edit_Estimate_price&&edit_Estimate_userTime){
            let edit_userPrice_mon = (Number(edit_original_price)-Number(edit_Estimate_price))/Number(edit_Estimate_userTime)
            $(this).closest('[lll]').find('[add_name=edit_userPrice_mon]').val(edit_userPrice_mon.toFixed(2))
        }else{
            $(this).closest('[lll]').find('[add_name=edit_userPrice_mon]').val('')
            return
        }
    })

    /**
     * 取消按钮点击时
     */
    $('.button_list').on('click','button',function(){
        if($(this).hasClass('cancel_btn')){
            $(this).closest('[lll]').removeClass('active')
        }
    })

    let msg = '文件正在上传，请勿重复点击！'
    // 上传文件
    $('#file_upload').change(function (e) {
        $(this).siblings('.import_tip_btn_box').find('button').removeClass('btn-grey').addClass('btn-success')
        $(this).siblings('.import_tip_btn_box').find('button').removeAttr('lock')
        msg = '文件正在上传，请勿重复点击！'
    })
    $('#import').find('button').click(function(e){
        "use strict";
        e.preventDefault()
        if($(this).hasClass('btn-success')){
            if($(this).html()=='确定导入'){
                //防止重复点击按钮
                if( $(this).attr('lock') ){
                    $('#yz_modal').html(msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                    return
                }
                $(this).attr('lock','lock')
                let that = this

                var formData = new FormData($("#file_form")[0]);
                $.ajax({
                    async : false,
                    cache : false,
                    type : "post",
                    data : formData,
                    url : '/Admin/Device/importDevice',
                    dataType : 'json',
                    contentType: false, //必须
                    processData: false, //必须
                    success : function(data) {
                        // console.log(data);
                        if(data.code==1){
                            $('#import').removeClass('active')
                            window.location.href = `/Admin/Device/index`//强制刷新
                            $(that).removeAttr('lock')
                        }else{
                            // console.log(222)
                            // console.log($('#yz_modal').html())
                            msg = data.msg
                            $('#yz_modal').html(msg)
                            $('#yz_modal').addClass('active')
                            tipShow()
                        }
                    }
                })
            }
        }

    })

    // 弹出来的小框框
    function tipShow(){
        window.tipBox = setTimeout(function(){
            // $('#yz_modal').removeClass('active')
            // $('#yz_modal').addClass('fadeOut')
            $('#yz_modal').removeClass('active')
            clearTimeout(tipBox)
        },2000)
    }

    //正则判断
    function regCheck(string,reg) {
        if(reg.test(string)){
            return true;
        }
        return false;
    }

    //当点击区域不在导入弹框中时则关闭弹框
    $(document).click(function(e){
        let $this = $(e.target);
        if($this.closest('#import').length==0){
            if($this.attr('href') != '#import' && $this.children().attr('href') != '#import'){
                $('#import').removeClass('active');
            }
        }
    })

    //拖动拖动拖动
        let add_box =document.getElementById("add_people");
        let edit_box =document.getElementById("edit_people");
        add_box.onmousedown = function(ev){
            if($(ev.toElement).attr('id')=='add_people'){
                ev =ev ||event;
                let oLeft = add_box.offsetLeft;
                let oTop = add_box.offsetTop;
                let a =ev.clientX-oLeft;
                let b =ev.clientY-oTop;
                add_box.onmousemove =function (ev){
                    ev = ev || event;
                    add_box.style.left =ev.clientX-a+'px';
                    add_box.style.top =ev.clientY-b+'px';
                    $(add_box).css({'cursor':'default'})
                }
            }
            
        }
        edit_box.onmousedown = function(ev){
            if($(ev.toElement).attr('id')=='edit_people'){
                ev =ev ||event;
                let oLeft = edit_box.offsetLeft;
                let oTop = edit_box.offsetTop;
                let a =ev.clientX-oLeft;
                let b =ev.clientY-oTop;
                edit_box.onmousemove =function (ev){
                    ev = ev || event;
                    edit_box.style.left =ev.clientX-a+'px';
                    edit_box.style.top =ev.clientY-b+'px';
                    $(edit_box).css({'cursor':'default'})
                }
            }
        
        }
        document.onmouseup =function(){
            add_box.onmousemove =function(){
                null;
            }
            edit_box.onmousemove =function(){
                null;
            }
        }
})